package com.big.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.big.app.dao.TalkDao;
import com.big.app.entity.FoodTalk;
import com.big.app.service.TalkService;
import com.big.app.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TalkServiceImpl implements TalkService {
    @Autowired
    private TalkDao dao;
    @Override
    public R selectAll(int fid) {
        QueryWrapper<FoodTalk> queryWrapper =new QueryWrapper();
        queryWrapper.eq("fid",fid);
        List<FoodTalk> talks = dao.selectList(queryWrapper);
        return new R(200,talks);
    }

    @Override
    @Transactional
    public R loveNum(Integer lovenum,int id) {
        QueryWrapper<FoodTalk> queryWrapper =new QueryWrapper();
        queryWrapper.eq("id",id);

        FoodTalk foodTalk1 = dao.selectOne(queryWrapper);
        Integer likenum = foodTalk1.getLikenum();
        likenum+=lovenum;
        FoodTalk foodTalk =new FoodTalk();
        foodTalk.setId(id);
        foodTalk.setLikenum(likenum);
        dao.updateById(foodTalk);
        return new R(200,"ok",null);
    }
}
